﻿using MongoDB.Config;
using MongoDB.Interface;

namespace MongoDB.Implement
{ /// <summary>
  /// mongo操作基类
  /// </summary>
	public class MongoBase<T> where T : new()
	{
		string connectionString = string.Empty;
		public static IDBHelper<T> mongoHelper = null;

		public MongoBase() { }

		/// <summary>
		/// 构造函数
		/// </summary>
		public MongoBase(string dataBase)
		{
			connectionString = ConfigSource.HomeDebugMongoDB;
			mongoHelper = new DBHelper<T>(new MongoDBConfig
			{
				IsAuthority = false,
				ConnectionString = connectionString,
				DataBase = dataBase
			});
		}

		/// <summary>
		/// 获取实体映射对象
		/// </summary>
		/// <returns></returns>
		public IDBHelper<T> GetDBHelper()
		{
			if (mongoHelper != null)
			{
				return mongoHelper;
			}
			return null;
		}

	}
}
